//
//  MemberTopView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/27.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MemberTopView.h"
#import "BuyMemberViewController.h"
#import "MemberTopViewCollectionViewCell.h"

static NSString *topCollectionCellID = @"topCollectionCellID";

@interface MemberTopView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) UIImageView *topBgIV;

@property (strong, nonatomic) UIImageView *blackIV;
@property (strong, nonatomic) UILabel *levelL;
@property (strong, nonatomic) UILabel *desL1;
@property (strong, nonatomic) UILabel *desL2;
@property (strong, nonatomic) UILabel *desL3;

@property (strong, nonatomic) UIImageView *immediateOpenIV;
@property (strong, nonatomic) UILabel *immediateL;

@property (strong, nonatomic) UICollectionView *topMemberCollectionView;

@end

@implementation MemberTopView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = WhiteColor;
        
        [self addSubview:self.topBgIV];
        [self addSubview:self.blackIV];
        [self addSubview:self.levelL];
        [self addSubview:self.desL1];
        [self addSubview:self.desL2];
        [self addSubview:self.desL3];
        [self addSubview:self.immediateOpenIV];
        [self addSubview:self.immediateL];
        [self addSubview:self.topMemberCollectionView];

    }
    
    return self;
}

#pragma mark -立即开通点击
- (void)immeditateOpenClick:(UIGestureRecognizer *)recognizer {
     [[NSNotificationCenter defaultCenter] postNotificationName:@"PUSHTOBUY" object:nil userInfo:nil];
   
}


#pragma mark -delegate \ datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    MemberTopViewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:topCollectionCellID forIndexPath:indexPath];
    
    return cell;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.topBgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.mas_centerX);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.width.mas_equalTo(jisuan(750));
        make.height.mas_equalTo(jisuan(300));
    }];
    [self.blackIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.mas_centerX);
        make.top.mas_equalTo(weakSelf.mas_top).with.offset(jisuan(84));
        make.width.mas_equalTo(jisuan(590));
        make.height.mas_equalTo(jisuan(350));
    }];
    [self.levelL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.blackIV.mas_left).with.offset(jisuan(50));
        make.top.mas_equalTo(weakSelf.blackIV.mas_top).with.offset(jisuan(50));
        make.width.mas_equalTo(jisuan(140));
        make.height.mas_equalTo(jisuan(80));
        
    }];
    [self.desL1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.levelL.mas_right).with.offset(jisuan(10));
//        make.top.mas_equalTo(weakSelf.levelL.mas_top).with.offset(jisuan(10));
        make.top.mas_equalTo(weakSelf.levelL.mas_top);
        make.right.mas_equalTo(weakSelf.blackIV.mas_right).with.offset(-jisuan(40));
        make.height.mas_equalTo(jisuan(28));
        
    }];
    
    [self.desL2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.levelL.mas_right).with.offset(jisuan(10));
//        make.bottom.mas_equalTo(weakSelf.levelL.mas_bottom).with.offset(-jisuan(10));
        make.bottom.mas_equalTo(weakSelf.levelL.mas_bottom);
        make.right.mas_equalTo(weakSelf.blackIV.mas_right).with.offset(-jisuan(40));
        make.height.mas_equalTo(jisuan(28));
        
    }];
    [self.desL3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.blackIV.mas_left).with.offset(jisuan(50));
        make.top.mas_equalTo(self.blackIV.mas_top).with.offset(jisuan(196)); // 182
        make.right.mas_equalTo(self.blackIV.mas_right).with.offset(-jisuan(40));
//        make.height.mas_equalTo(jisuan(28));
        
    }];
    [self.immediateOpenIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.mas_centerX);
        make.top.mas_equalTo(weakSelf.blackIV.mas_top).with.offset(jisuan(290));
        make.width.mas_equalTo(jisuan(220));
        make.height.mas_equalTo(jisuan(88));
    }];
    [self.immediateL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.immediateOpenIV.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.immediateOpenIV.mas_centerY).with.offset(-jisuan(4));
    }];
//    [self.topMemberCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.mas_equalTo(weakSelf.mas_left).with.offset(jisuan(20));
//        make.right.mas_equalTo(weakSelf.mas_right);
//        make.bottom.mas_equalTo(weakSelf.mas_bottom).with.offset(-jisuan(20));
//        make.height.mas_equalTo(jisuan(102));
//    }];
}


#pragma mark -lazy
- (UICollectionView *)topMemberCollectionView {
    
    if (!_topMemberCollectionView) {
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(jisuan(230), jisuan(100));
        flowLayout.minimumInteritemSpacing = jisuan(20);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

        _topMemberCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _topMemberCollectionView.backgroundColor = WhiteColor;
        _topMemberCollectionView.showsVerticalScrollIndicator = NO;
        _topMemberCollectionView.showsHorizontalScrollIndicator = NO;
        
        _topMemberCollectionView.delegate = self;
        _topMemberCollectionView.dataSource = self;
        
        [_topMemberCollectionView registerClass:[MemberTopViewCollectionViewCell class] forCellWithReuseIdentifier:topCollectionCellID];
        
        if (@available(iOS 11.0, *)) {
            _topMemberCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
    }
    
    return _topMemberCollectionView;
}

- (UIImageView *)topBgIV {
    
    if (!_topBgIV) {
        
        _topBgIV = [[UIImageView alloc] init];
        _topBgIV.contentMode = UIViewContentModeScaleAspectFit;
        _topBgIV.image = [UIImage imageNamed:@"MemberTopBgView"];
    }
    
    return _topBgIV;
}

- (UIImageView *)blackIV {
    
    if (!_blackIV) {
        
        _blackIV = [[UIImageView alloc] init];
        _blackIV.contentMode = UIViewContentModeScaleAspectFit;
        _blackIV.image = [UIImage imageNamed:@"memberDesViewbg"];
    }
    
    return _blackIV;
}

- (UILabel *)levelL {
    
    if (!_levelL) {
        
        _levelL = [[UILabel alloc] init];
        _levelL.text = @"VIP";
        _levelL.textColor = Colorf8e3ac;
        _levelL.font = Font(80);
//        _levelL.font = [UIFont fontWithName:@"MFYueYuan_Noncommercial-Regular" size:jisuan(80)];
        _levelL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _levelL;

}

- (UILabel *)desL1 {
  
    if (!_desL1) {
        
        _desL1 = [[UILabel alloc] init];
        _desL1.text = @"爱淘帮会员，专属超值商品";
        _desL1.textColor = Colorf8e3ac;
        _desL1.font = Font(28);
        _desL1.textAlignment = NSTextAlignmentLeft;
        
    }
    return _desL1;
}

- (UILabel *)desL2 {
    
    if (!_desL2) {
        
        _desL2 = [[UILabel alloc] init];
//        _desL2.text = @"会员趣豆抵扣可达80%～100%";
        _desL2.textColor = Colorf8e3ac;
        _desL2.font = Font(20);
        _desL2.textAlignment = NSTextAlignmentLeft;
        
    }
    
    return _desL2;
}
- (UILabel *)desL3 {

    if (!_desL3) {
        
        _desL3 = [[UILabel alloc] init];
        _desL3.text = @"开通会员惊喜多多，优惠不断";
        _desL3.textColor = Colorf8e3ac;
        _desL3.numberOfLines = 2;
        _desL3.font = Font(20);
        _desL3.textAlignment = NSTextAlignmentLeft;
        
    }
    
    return _desL3;
}

- (UIImageView *)immediateOpenIV {
    
    if (!_immediateOpenIV) {
        
        _immediateOpenIV = [[UIImageView alloc] init];
        _immediateOpenIV.contentMode = UIViewContentModeScaleAspectFit;
        _immediateOpenIV.image = [UIImage imageNamed:@"memberImmediateOpenBG"];
    
        _immediateOpenIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer  alloc] initWithTarget:self action:@selector(immeditateOpenClick:)];
        [_immediateOpenIV addGestureRecognizer:recognizer];
    }
    
    return _immediateOpenIV;
}

- (UILabel *)immediateL {
    
    if (!_immediateL) {
        
        _immediateL = [[UILabel alloc] init];
        _immediateL.text = @"立即开通";
        _immediateL.textColor = Color333333;
        _immediateL.textAlignment = NSTextAlignmentCenter;
//        _immediateL.font = Font(28);
        _immediateL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:jisuan(28)];
        
    }
    return _immediateL;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
